! function(window, initFun) {
    "object" == typeof exports && "undefined" != typeof module ? module.exports = initFun() : "function" == typeof define && define.amd ? define(initFun) : window.uni = initFun()
}(this, function() {
    "use strict";
    var uni = {},
        ids = [],
        isUni = /uni-app/i.test(navigator.userAgent),
        webId = "__uniapp__service",
        w = "WEB_INVOKE_APPSERVICE",
        i = function(method, paras) {
            if (0 === ids.length && isUni) {
                var n = plus.webview.currentWebview();
                if (!n) throw new Error("plus.webview.currentWebview() is undefined");
                var t = n.parent();
                if (!t) throw new Error("plus.webview.currentWebview().parent() is undefined");
                ids.push(t.id)
            }
            var a = {
                options: {
                    timestamp: +new Date
                },
                name: uni,
                arg: paras
            };
            if (isUni) {
                var r = JSON.stringify(a);
                plus.webview.getWebviewById(webId) ? plus.webview.postMessageToUniNView({
                    type: w,
                    args: {
                        data: a,
                        webviewIds: ids
                    }
                }, webId) : plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("' + w + '",' + r + "," + JSON.stringify(ids) + ");")
            } else window.parent.postMessage({
                type: w,
                data: a,
                pageId: ""
            }, "*")
        };
    uni.navigateTo = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).url;
        i("navigateTo", {
            url: encodeURI(e)
        })
    }, uni.navigateBack = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).delta;
        i("navigateBack", {
            delta: parseInt(e) || 1
        })
    }, uni.switchTab = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).url;
        i("switchTab", {
            url: encodeURI(e)
        })
    }, uni.reLaunch = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).url;
        i("reLaunch", {
            url: encodeURI(e)
        })
    }, uni.redirectTo = function() {
        var e = (0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {}).url;
        i("redirectTo", {
            url: encodeURI(e)
        })
    }, uni.getEnv = function(e) {
        uni(isUni ? {
            plus: !0
        } : {
            h5: !0
        })
    }, uni.postMessage = function() {
        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : {};
        i("postMessage", e.data || {})
    };
    var n = {};
    "undefined" != typeof wx && wx.miniProgram && (n.navigateTo = wx.miniProgram.navigateTo, n.navigateBack = wx.miniProgram.navigateBack, n.switchTab = wx.miniProgram.switchTab, n.reLaunch = wx.miniProgram.reLaunch, n.redirectTo = wx.miniProgram.redirectTo, n.postMessage = wx.miniProgram.postMessage, n.getEnv = wx.miniProgram.getEnv);
    var t = {}; - 1 < navigator.userAgent.indexOf("AlipayClient") && "undefined" != typeof my && (t.navigateTo = my.navigateTo, t.navigateBack = my.navigateBack, t.switchTab = my.switchTab, t.reLaunch = my.reLaunch, t.redirectTo = my.redirectTo, t.postMessage = my.postMessage, t.getEnv = my.getEnv);
    var a = {};
    "undefined" != typeof swan && swan.webView && (a.navigateTo = swan.webView.navigateTo, a.navigateBack = swan.webView.navigateBack, a.switchTab = swan.webView.switchTab, a.reLaunch = swan.webView.reLaunch, a.redirectTo = swan.webView.redirectTo, a.postMessage = swan.webView.postMessage, a.getEnv = swan.webView.getEnv);
    var r = {};
    "undefined" != typeof tt && tt.miniProgram && (r.navigateTo = tt.miniProgram.navigateTo, r.redirectTo = tt.miniProgram.redirectTo, r.reLaunch = tt.miniProgram.reLaunch, r.switchTab = tt.miniProgram.switchTab, r.navigateBack = tt.miniProgram.navigateBack);
    var g = navigator.userAgent,
        c = /uni-app/i.test(g),
        v = /micromessenger/i.test(g),
        u = /AlipayClient/.test(g),
        p = /swan/i.test(g),
        m = /toutiaomicroapp/i.test(g),
        l = {},
        b = function() {
            window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady", {
                bubbles: !0,
                cancelable: !0
            }))
        };
    return c ? (l = u, window.plus && /complete|loaded|interactive/.test(document.readyState) ? b() : document.addEventListener("plusready", b)) : v ? (l = n, window.WeixinJSBridge && WeixinJSBridge.invoke ? b() : document.addEventListener("WeixinJSBridgeReady", b)) : (l = u ? t : p ? a : m ? r : u, document.addEventListener("DOMContentLoaded", b)), l
});
